<?php

declare(strict_types=1);

namespace App\AdminApi\Module\System\Api;

use App\AdminApi\AdminApiBasicsController;
use App\AdminApi\Module\System\Service\SystemService;
use App\Sys;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\{Controller, GetMapping, PostMapping};
use Psr\Http\Message\ResponseInterface;
use Zms\Guard\Auth;
use Zms\HyperfResponse\Response;

#[
    Auth(guard: self::GUARD, label: ['系统管理'], app: self::APP),
    Controller(prefix: "/admin-api/system-configure", server: self::SERVER)
]
class ConfigureController extends AdminApiBasicsController
{
    #[Inject]
    protected SystemService $service;

    #-----------------------------------------------------系统设置------------------------------------------------------#
    #[
        GetMapping('settings'),
        Auth(label: ['系统配置'], sign: 'system.configure', describe: "查看系统配置", view: '/system/configure/index')
    ]
    public function getSttings(): ResponseInterface
    {
        return Response::Api()->success(
            data: $this->service->getConfigureForm(
                'system',
                $this->request->getPathInfo(),
                '系统配置修改'
            )
        );
    }


    #[
        PostMapping('settings'),
        Auth(label: ['修改'], relyon: ['system.configure'], describe: "修改系统配置")
    ]
    public function setSettings(): ResponseInterface
    {
        $this->service->setConfigure('system', $this->request->post());
        Sys::cache()->clear();
        return Response::Api()->success("设置成功");
    }


    #-----------------------------------------------------地图设置------------------------------------------------------#
    #[
        GetMapping('map'),
        Auth(label: ['后台设置'], sign: 'system.configure.map', view: '/system/configure/map')
    ]
    public function getMap(): ResponseInterface
    {
        return Response::Api()->success(
            data: $this->service->getConfigureForm('map', $this->request->getPathInfo(), '腾讯地图配置', '120px')
        );
    }

    #[
        PostMapping('map'),
        Auth(label: ['后台设置'], relyon: ['system.configure.map'])
    ]
    public function setMap(): ResponseInterface
    {
        $this->service->setConfigure('map', $this->request->post());
        Sys::cache()->clear();
        return Response::Api()->success("设置成功");
    }


    #-----------------------------------------------------违禁词汇------------------------------------------------------#
    #[
        GetMapping('violate'),
        Auth(label: ['后台设置'], sign: 'system.configure.violate', view: '/system/configure/violate')
    ]
    public function getViolate(): ResponseInterface
    {
        return Response::Api()->success(
            data: $this->service->getConfigureForm('violate', $this->request->getPathInfo(), '腾讯地图配置', '120px')
        );
    }

    #[
        PostMapping('violate'),
        Auth(label: ['后台设置'], relyon: ['system.configure.violate'])
    ]
    public function setViolate(): ResponseInterface
    {
        $this->service->setConfigure('violate', $this->request->post());
        Sys::cache()->clear();
        return Response::Api()->success("设置成功");
    }


    #-----------------------------------------------------Aip配置------------------------------------------------------#
    #[
        GetMapping('ai'),
        Auth(label: ['后台设置'], sign: 'system.configure.ai', view: '/system/configure/ai')
    ]
    public function getAi(): ResponseInterface
    {
        return Response::Api()->success(
            data: $this->service->getConfigureForm('ai', $this->request->getPathInfo(), '腾讯地图配置', '120px')
        );
    }


    #[
        PostMapping('ai'),
        Auth(label: ['后台设置'], relyon: ['system.configure.ai'])
    ]
    public function setAi(): ResponseInterface
    {
        $this->service->setConfigure('ai', $this->request->post());
        Sys::cache()->clear();
        return Response::Api()->success("设置成功");
    }
}